$(document).ready(function(){
    //回到顶部
    var bt = $('#backtop');            

            $(window).scroll(function() {

                    var st = $(window).scrollTop();

                    if(st > 30){

                            bt.show();

                    }else{

                            bt.hide();

                    }

            });
            //showNums 打开了多少个页面
            showNums    = getCookie('showNums');
            if(isNaN(showNums))
            {
                //alert(showNums);
                setCookie('showNums',0);
            }
            else
            {
                if(parseInt(showNums) <= 5)
                {
                    showNums++;
                    setCookie('showNums',showNums);
                }
                else
                {
                    var pathname = window.location.pathname;//取当前url的文件名
                    signup_path = pathname.indexOf("signup");//判断当前页面是登陆页或者注册页
                    signin_path = pathname.indexOf("signin");
                    if (signup_path == -1 && signin_path == -1 && getCookie('user_id') == undefined)    
                    {
                        //logindialog();   
                    }                    
                    setCookie('showNums',0);
                }
            }
})
//菜谱列表页削效果
$(function(){
    $("#fliterstyle1 dt").click(function(){
        var _this=$(this);
        if(_this.parent().hasClass("on")){
        }else{
            _this.parents(".tabcon").find("dl.on").find("dd").slideUp(function(){
            });
            _this.parents(".tabcon").find("dl.on").removeClass("on");
            _this.next().slideDown(function(){
                _this.parent().find(".long").slideDown();
            });
            _this.parent().addClass("on");
        }
    });
    $("#fliterstyle1 .tab li").click(function(){
        var po = $(this).attr("po");
        if(!$(this).hasClass("current")){
            $(this).siblings().removeClass("current");
            $(this).addClass("current");
        }
        $("#fliterstyle1 .tabcon").each(function(){
            if($(this).attr("po") == po){
                $(this).siblings(".tabcon").hide();
                $(this).show();
            }
        });
    });
}); 
//菜谱列表页削效果结束
function buildURL(a){
    a=a.replace(/^\s+|\s+$/g,"");
    if(a=="")
    {
        return ""
    }
    s=utfurl(a);
    s=s.replace(/%20/g,"+");
    return s.replace(/%(5E|2E|2D|2F|3B|3F|40|2C|26|3A|3D|2B|24)/g,"_$1");
}
function utfurl(d){
    var d=toutf8(d);
    var e;
    var a="";
    for(var b=0;b<d.length;b++){
        if(utfurl.okURIchars.indexOf(d.charAt(b))==-1){
            a+="%"+toHex(d.charCodeAt(b))
        }else{
            a+=d.charAt(b)
        }
    }
    return a
}
function toutf8(e){
    var f,d;
    var a="";
    var b=0;
    while(b<e.length){
        f=e.charCodeAt(b++);
        if(f>=56320&&f<57344){
            continue
        }
        if(f>=55296&&f<56320){
            if(b>=e.length){
                continue
            }
            d=e.charCodeAt(b++);
            if(d<56320||f>=56832){
                continue
            }
            f=((f-55296)<<10)+(d-56320)+65536
        }
        if(f<128){
            a+=String.fromCharCode(f)
        }else{
            if(f<2048){
                a+=String.fromCharCode(192+(f>>6),128+(f&63))
            }else{
                if(f<65536){
                    a+=String.fromCharCode(224+(f>>12),128+(f>>6&63),128+(f&63))
                }else{
                    a+=String.fromCharCode(240+(f>>18),128+(f>>12&63),128+(f>>6&63),128+(f&63))
                }
            }
        }
    }
    return a
}
toHex.hexchars="0123456789ABCDEF";
function toHex(a){
    return toHex.hexchars.charAt(a>>4)+toHex.hexchars.charAt(a&15)
}
utfurl.okURIchars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

function Search()
{
    var url = $("#searchForm").attr('action');
    if ($("#global_search_inpt").val() == '')
    {
        location.href= url + buildURL('');
        return false;
    }
    else
    {
        location.href= url + buildURL($("#global_search_inpt").val());
    }
    return false;
}
function JS_HoverToggle()
{
    $('[JS_SHT]').hover(JS_hoverShow,JS_hoverHide);
    function JS_hoverShow()
    {
        obj    = $(this);
        $('[JS_DHT='+obj.attr('JS_SHT')+']').show();
    }
    function JS_hoverHide()
    {
        obj    = $(this);
        $('[JS_DHT='+obj.attr('JS_SHT')+']').hide();
    }
}
function JS_PlaceHolder()
{
    $('input[JS_PHN]').live('blur',JS_placeBlur);
    $('input[JS_PHN]').live('focus',JS_placeFocus);
    function JS_placeBlur()
    {
        var obj    = $(this);
        if(obj.val()==''||$.trim(obj.val())=='')
        {
            obj.val(obj.attr('JS_PHN'));
        }
    }
    function JS_placeFocus()
    {
        var obj    = $(this);
        if(obj.val()==obj.attr('JS_PHN')||$.trim(obj.val())==obj.attr('JS_PHN'))
        {
            obj.val('');
        }
    }
}
/**
* 校验 邮箱
* 最多可以三个参数
* 1.邮箱 2.成功的回调函数 3.失败的回调函数 4.是否校验邮箱已经注册
*/
function JS_CheckEmail()
{
	var errtag	= true;
	var email	= arguments[0];
	var suc	= arguments[1];
	var err	= arguments[2];
	var emalr    = /^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/i;
	var checktype	= arguments[3];
	if(email=='')
	{
		err('请输入邮箱');
		return false;
	}
    if(emalr.test(email))
    {
    	if(arguments[3])
    	{
			$.ajax(
				{
					type	: 'post',
					url	: '/uajax/ajaxemail',
					data	: '&email='+email,
					async	: false,
					dataType	: 'json',
					success	: function(msg)
					{
						if(msg.status=='OK')
						{
							if(msg.data=='OK')
							{
								if(checktype == 'login')
								{
									errtag	= false;
									err('该邮箱未注册，<a href="/signup.html" target="_self">马上注册</a>');
								}
								else if(checktype == 'register')
								{
									
									errtag	= true;
									suc();
								}
								else if(checktype == 'haveBinding')
								{
									errtag	= false;
									err('该邮箱未注册，不能绑定');
								}
							}
							else
							{
								if(checktype == 'login')
								{
									errtag	= true;
									suc();
								}
								else if(checktype == 'register')
								{
									errtag	= false;
									err('该邮箱已注册，请输入其他邮箱');
								}
								else if(checktype == 'haveBinding')
								{
									errtag	= true;
									suc();
								}
							}
						}
						else
						{
							errtag	= false;
							err('请输入正确的邮箱格式');
						}
					}
				})
			return errtag;
		}
		else
		{
			if(arguments[1]!=undefined&&$.isFunction(arguments[1]))
		    {
				arguments[1]();
		    }
		    return true;
		}
    }
    else
    {
        if(arguments[2]!=undefined&&$.isFunction(arguments[2]))
        {
			arguments[2]('请输入正确的邮箱格式！');
        }
        return false;
    }
}
/**
* 校验 昵称
* 最多可以三个参数
* 1.昵称 2.成功的回调函数 3.失败的回调函数
*/
function JS_CheckNickname()
{
    var errortag    = true;
    var nickname    = arguments[0];
    var su    = arguments[1];
    var er    = arguments[2];
    nickname    = $.trim(nickname);
    $("#username").val(nickname);
    regnickname    = /^[0-9A-Za-z_\u4E00-\u9FA5]{0,}$/;
    if(regnickname.test(nickname))
    {
        if(strlen(nickname) >= 4 && strlen(nickname) <= 20)
        {
            $.ajax(
            {
                type    : 'post',
                url    : '/uajax/ajaxusername',
                data    : '&username='+nickname,
                async    : false,
                dataType    : 'json',
                success    : function(msg)
                {
                    if(msg.status=='OK')
                    {
                        errortag    = false;
                         if(er!=undefined&&$.isFunction(er))
                        {
                            er('这个昵称已经存在，请输入其他昵称');
                        }
                    }
                    else
                    {
                        errortag    = true;
                        if(su!=undefined&&$.isFunction(su))
                        {
                            su();
                        }
                    }
                }
            })
            return errortag;
        }
        else
        {
            if(arguments[2]!=undefined&&$.isFunction(arguments[2]))
            {
                if(strlen(nickname) > 20)
                {
                    arguments[2]('不超过10个汉字');
                }
                else
                {
                    if(nickname=='')
                    {
                        arguments[2]('请输入你的昵称');
                    }
                    else
                    {
                        arguments[2]('昵称太短了');
                    }
                }
            }
            return false;
        }
    }
    else
    {
        arguments[2]('支持中英文、数字或者“_”');
    }
}
/**
* 校验 密码
* 最多可以三个参数
* 1.密码 2.成功的回调函数 3.失败的回调函数
*/
function JS_CheckPassword()
{
    var pwd    = arguments[0];
    if(pwd != '' && pwd.length >= 6)
    {
        if(arguments[1]!=undefined&&$.isFunction(arguments[1]))
        {
            arguments[1]();
        }
        return true;
    }
    else
    {
        if(arguments[2]!=undefined&&$.isFunction(arguments[2]))
        {
            if(pwd=='')
            {
                arguments[2]('请输入密码');
            }
            else
            {
                arguments[2]('密码长度为6-20位，不能含有空格');
            }
        }
        return false;
    }
}
/**
* 统一登陆操作参数列表
* 用户名
* 密码
* 是否记住
* 成功的回调函数
* 失败的回调函数
*/
function JS_Login()
{
    var username    = arguments[0];
    var passwd        = arguments[1];
    var remember    = arguments[2];
    var captcha    = arguments[3];
    var loginsce    = arguments[4];
    var loginerror    = arguments[5];
    $.ajax(
    {
        type    : 'post',
        url    : '/uajax/login',
        data    : '&username='+username+'&password='+passwd+'&remember='+remember+'&captcha='+captcha,
        dataType: 'json',
        success    : function(msg)
        {
            if (msg.status == 'OK')
            {
                // if ok flush the login form
                loginsce(msg.data);
            }
            else
            {
                loginerror(msg.data); 
            }
        }
    })
    return false;
}
/**
* 同统一注册操作参数列表
* 用户名
* 密码
* 是否记住
* 成功的回调函数
* 失败的回调函数
*/
function JS_Signup()
{
    var email    = arguments[0];
    var pwd            = arguments[1];
    var username    = arguments[2];
    var captcha    = arguments[3];
    var loginsce    = arguments[4];
    var loginerror    = arguments[5];
    $.ajax(
    {
        type    : 'post',
        url    : '/uajax/ajaxregister',
        data    : '&email='+email+'&password='+pwd+'&username='+username+'&captcha='+captcha,
        dataType    : 'json',
        async    : false,
        success    : function (msg)
        {
            if(msg.status=='OK')
            {
                loginsce();
            }
            else
            {
                loginerror(msg.data);
            }
        }
    })
}

function isChinese(str)
{
    var lst = /[u00-uFF]/;
    return !lst.test(str);
}
function strlen(str)
{
    var strlength=0;
    for (i=0;i<str.length;i++)
   {
      if (isChinese(str.charAt(i))==true)
         strlength=strlength + 2;
      else
         strlength=strlength + 1;
   }
   return strlength;
}
function loadding()
{
    if(arguments[0])
    {
        var obj    = arguments[0];
    }
    else
    {
        return false;
    }
    var showstatus    = arguments[1]!=undefined&&arguments[1]==false    ?  true : false;
    var loaddingimg    = $('<img src="/img/loading.gif" />');
    this.stop    = function ()
    {
        obj.show();
        if(obj.prev().is('img[src=/img/loading.gif]'))
        {
            obj.prev().remove();
        }
    }
    this.loadding    = function ()
    {
        obj.toggle(showstatus);
        obj.before(loaddingimg);
    }
    return this;
}
/**
 * @time: 2012-07-05
 * 
 * @desc: 弹出登录信息框
 * @author: jack
**/
function logindialog()
{
    var h = $(window).height() / 2 - 150;
    var w = $(window).width() / 2 - 290;
    var id = 'LoginDialogIndex';
    var html = '<div id="'+ id +'" class="dlceng r5" style="z-index: 9999; top: '+ h +'px; left: '+ w +'px; position: fixed; display: block; ">'
            html += '<div class="dlccontent" id="deng">'
                html += '<a href="javascript:void(0);" class="scengb dlclose"></a>'        
                html += '<div class="tith">'
                    html += '<h3>登录</h3>'                
                html += '</div>'
                html += '<div class="dlrig lirdb">'
                html += '<form onsubmit="return ajaxlogin();" method="post" action="/">'
                    html += '<div class="mt30 clearfix">'
                        html += '<label>邮箱</label>'
                        html += '<div class="iput"><input id="username" name="username" value="" onblur="checkemail()" class="centext r5" type="text"></div>'                         
                    html += '</div>'
                    html += '<div class=" mt15 clearfix">'
                        html += '<label>密码</label>'
                        html += '<div class="iput"><input id="password" name="password" value="" onblur="checkpassword()" class="centext r5" maxlength="20" type="password">'
                            html += '<span class="mt8 dblok"><input name="remember" type="checkbox" value="1" id="remember" checked="checked" class="czl"> 记住我&nbsp;&nbsp;&nbsp;<font class="flin">|</font>&nbsp;&nbsp;&nbsp;<a href="/index.php/user/forgot_password" title="忘记密码">忘记密码</a></span></div>'                    
                    html += '</div>'
                    html += '<div class="btloo">'
                        html += '<button id="doLogin" type="submit" class="btncengdl">登录</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="ff0 hidden">邮箱和密码不匹配</span>'
                    html += '</div>'
                    html += '<input id="forward" type="hidden" value="">'
                    html += '</form>'            
                html += '</div>'
                html += '<div class="dlrim">'
                    html += '<p>还没有账号？<a href="javascript:void(0);" class="btljzc r3 mls" id="ljzc">立即注册</a></p>'
                    html += '<span><br>用其他账号登录</span>'
                    html += '<p class="mtm">'
                        html += '<a class="lg_sina" href="/user/api_connect/Sina" target="_blank"></a>'
                        html += '<a class="lg_qq" href="/user/api_connect/QQ" target="_blank"></a>'
                    html += '</p>'    
                    html += '</p>'
                html += '</div>'  
            html += '</div>'
            html += '<div class="zcccontent" id="zhu" style="display:none">'
                html += '<a href="javascript:void(0);" class="scengb dlclose"></a>'        
                html += '<div class="tith">'
                    html += '<h3>注册</h3>'                
                html += '</div>'
                html += '<div class="zcrig lirdb">'
                    html += '<form action="/" method="post" onsubmit="return ajaxsignup();">'
                    html += '<div class="mt30 clearfix">'
                        html += '<label>邮箱</label>'
                        html += '<div class="iput"><input id="zhuemail" name="zhuemail" value="" class="centext r5" type="text"></div>'                         
                    html += '</div>'
                    html += '<div class=" mt15 clearfix">'
                        html += '<label>密码</label>'
                        html += '<div class="iput"><input id="zhupasswd" name="zhupasswd" value="" class="centext r5" maxlength="20" type="password"></div>'                    
                    html += '</div>'
                    html += '<div class=" mt15 clearfix">'
                        html += '<label>邮箱</label>'
                        html += '<div class="iput"><input id="email" name="email" value="" class="centext r5" maxlength="20" type="text"></div>'                    
                    html += '</div>'
                    html += '<div class="btloo">'
                        html += '<button id="doLogin" type="submit" class="btncengdl">注册</button>'
                    html += '</div>' 
                    html += '</form>'           
                html += '</div>'
                html += '<div class="zcrim">'
                    html += '<p>已有账号？<a href="#" class="btdengb mls" id="msdl">马上登录</a></p>'
                    html += '<span><br>用其他账号登录</span>'
                    html += '<p class="mtm">'
                        html += '<a class="lg_sina" href="/user/api_connect/Sina" target="_blank"></a>'
                        html += '<a class="lg_qq" href="/user/api_connect/QQ" target="_blank"></a>'
                    html += '</p>'
                html += '</div>'  
            html += '</div>'
        html += '</div>'
    $('body').append(html);
    $("#"+id).dialog({
        resizable:false,
        draggable:false,
        modal:true
    });
    window.api.showtype='current';
    $("#ljzc").click(function(){
        $("#deng").slideUp()
        $("#zhu").slideDown()
    });
    $("#msdl").click(function(){
        $("#zhu").slideUp()
        $("#deng").slideDown()
    });
    $(".dlclose").live("click",function(){
        $("#"+id).remove();
        window.api.showtype='newwindow';
        $("#"+id).dialog("close");
    });
    $("#email").focus();
}




/**
 * @desc: 菜单分组弹出框
 * @author: jack
**/
function tipCaidanGroup(str)
{
    var h  = $(window).height() / 2 - 183;
    var w  = $(window).width() / 2 - 158;
    var id = 'caidanGroupDialogIndex';
    var html='<div id="' + id + '" randnum="'+ parseInt(1000*Math.random()) +'" class="cdceng r5" style="z-index: 9999; top: '+ h +'px; left: '+ w +'px; position: fixed;">';
            html += '<div class="cdcontent r3">';
                html += '<a href="javascript:void(0);" class="scengb dlclose"></a>';
                    html += '<div class="tith"><h3 class="pll">选择要添加的栏目</h3></div>';
                        html += '<div class="cdsecler"><ul class="pl25 mtl">';
                            html += str;
                            html += '</ul></div>';
                        html += '<div class="ml25 mt30">';
                    html += '<button id="doLogin" type="button" class="btnpl">确定</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void(0);" class="caidangroup">取消</span>';
                html += '</div>';
            html += '</div>';
        html += '</div>';
    $('body').append(html);
    $("#"+id).dialog({
        resizable:false,
        draggable:false,
        modal:true
    });
    $(".dlclose").live("click",function(){
        $("#"+id).remove();
        $("#"+id).dialog("close");
    });
}

/**
 * @desc:   错误提示框信息
 * @author: jack
**/
function showerrorinfo(title, str)
{
    var h  = $(window).height() / 2 - 90;
    var w  = $(window).width() / 2 - 142;
    var id = 'showerrorinfo';
    var html = '<div id="'+ id +'" randnum="'+ parseInt(1000*Math.random()) +'" class="wrongceng r5" style="z-index:9999; top:'+ h +'px; left:'+ w +'px; position:fixed;">'
            html += '<div class="wrcontent">'
                html += '<a href="javascript:void(0);" class="scengb dlclose"></a>'        
                    html += '<div class="tith">'
                        html += '<h3 class="pll">'+ title +'</h3>'                
                    html += '</div>'
                    html += '<div class="wrmword">'
                    html += str;        
                    html += '</div>'                    
            html += '</div>'
       html += '</div>';
    $('body').append(html);
    $("#"+id).dialog({
        resizable:false,
        draggable:false,
        modal:true
    });
    setTimeout(function(){$("#"+id).dialog("close");},2000);
    $(".dlclose").live("click",function(){
        $("#"+id).remove();
        $("#"+id).dialog("close");
    });
}

//jQuery.confirm
(function($){
    var h  = $(window).height() / 2 - 110;
    var w  = $(window).width() / 2 - 210;
    var confirmBoxIndex=0;
    $.fn.confirm = function(options){
        var defaults = {
            yes: '确定',
            no : '取消',
            title: '提示信息',
            msg: 'error',
            callback:null
        };
        var opts = $.extend(defaults, options);
        confirmBoxIndex++;
        var id="confirmBox"+confirmBoxIndex;
        var html = '<div id="'+id+'" class="wrongceng r5" style="z-index:9999;top:'+ h +'px;left:'+ w +'px;position:fixed;display:block; ">'
                html += '<div class="wrcontent">'
                    html += '<a href="javascript:void(0)" class="no scengb dlclose"></a>'    
                    html += '<div class="tith">'
                        html += '<h3 class="pll">提示</h3>'
                    html += '</div>'
                    html += '<div class="tisword">'
                        html += opts.msg
                    html += '</div>'
                    html += '<div class="tisbtn">'
                        html += '<button  type="button" class="yes btndl mrm">确定</button><button  type="button" class="no btndl">取消</button>'
                    html += '</div>'                        
                html += '</div>'
            html += '</div>';
        $('body').append(html);
        var dialog=$('#'+id).dialog({
            title:opts.title,
            width:285,
            resizable: false,
            draggable: true,
            modal: true,
            close: function(event,ui){$(this).dialog('destory').remove();}
        });
        $(".yes").click(function(){
            $("#"+id).remove();
            $("#"+id).dialog('close');
            opts.callback();
        });
        $(".no").click(function(){
            $("#"+id).remove();
            $("#"+id).dialog('close');
        });
        return dialog;
    };
})(jQuery);

function checkemail(checktype,emailid)
{
	var checktype	= arguments[0];
	if(arguments[1]==undefined)
	{
		var emailid	= 'email';
	}
	else
	{
		var emailid	= arguments[1];
	}
	return JS_CheckEmail($('#'+emailid).val(),oktip($('#'+emailid)),errortip($('#'+emailid)),checktype);
}
function checkpassword()
{
	if(arguments[0]==undefined)
	{
		var passwdid	= 'password';
	}
	else
	{
		var passwdid	= arguments[0];
	}
	return JS_CheckPassword($('#'+passwdid).val(),oktip($('#'+passwdid)),errortip($('#'+passwdid)));
}
function dialogchecknickname()
{
	return JS_CheckNickname($('#username').val(),oktip($('#username')),errortip($('#username')));
}
function errortip(obj)
{
    var text    = '邮箱和密码不匹配';
    return function ()
    {
        if(arguments[0]!=undefined&&arguments[0]!='')
        {
            text    = arguments[0];
        }
        obj.parents('.iput').next().html(text).addClass('lowrong').addClass('mll').removeClass('loright').removeClass('mtl15');
    }
}
function oktip(obj)
{
    return function ()
    {
        obj.parents('.iput').next().html(' ').addClass('loright').addClass('mtl15').removeClass('lowrong').removeClass('mll');
    }
}
function login()
{
    function success()
    {
        if ($("#forward").val() == '')
        {
            window.location.reload();
        }
        else
        {
            window.location.href=$('#forward').val();
        }
    }
    function error(err)
    {
        errortip($('#password'))(err);
        return false;
    }
    resultcheckemail    = checkemail('login');
    resultcheckpassword    = checkpassword();
    if(resultcheckemail&&resultcheckpassword)
    {
        var remember    = $('#remember').is(':checked') ? '1':'0';
        JS_Login($('#email').val(),$('#password').val(),remember,$('#captcha').val(),success,error);
    }
    return false;
}
function ajaxlogin(obj)
{
    obj    = $(obj);
    var username    = $('[name=username]').val();
    var password    = $('[name=password]').val();
    var remember    = $('[name=remember]').is(':checked') ? '1':'0';
    if(username=='' || username=='邮箱')
    {
        window.location.href='/index.php/user/login';
        return false;
    }
    $.ajax(
    {
        type    : 'post',
        url    : '/uajax/login',
        data    : '&username='+username+'&password='+password+'&remember='+remember,
        dataType: 'json',
        success    : function(msg)
        {
            if (msg.status == 'OK')
            {
                // if ok flush the login form
                window.location.reload();
                //hideliginlead    = true;
                //$("#toplogin").load('/ajax/headinfo');
                //$("#login_info").load('/ajax/loginfo');
            }
            else
            {
                if (msg.status == 'ERR_CAP')
                {
                    window.location.href='/index.php/user/login/'+username;
                    return false;
                }
                else
                {
                    window.location.href='/index.php/user/login/'+username;
                    return false;
                }
            }
        }
    })
    return false;
}
function ajaxsignup(obj)
{
    obj    = $(obj);
    var username    = $('[name=zhuemail]').val();
    var passwd    = $('[name=zhupasswd]').val();
    var email  = $('[name=email]').val();
    if(checkemail('register','zhuemail')&&dialogchecknickname()&&checkpassword('zhupasswd'))
    {
	    $.ajax(
	    {
	        type    : 'post',
	        url    : '/index.php/uajax/register',
	        data    : '&username='+username+'&password='+passwd+'&email='+email,
	        dataType: 'json',
	        success    : function(msg)
	        {
	            if (msg.status == 'OK')
	            {
	                window.location.reload();
	            }
	            else
	            {
	                window.location.href='/?user/register.html?email='+username+'&email1='+email;
	                return false;
	            }
	        }
	    })
    }
    else
    {
    	window.location.href='/?user/register.html?email='+username+'&email2='+email;
    }
    return false;
}
function setCookie(name,value)
{
    var exdate=new Date()
    exdate.setDate(exdate.getDate()+48)
    document.cookie = name + "=" + escape(value) + "; expires=" + exdate.toUTCString() + "; path=/";
}
function getCookie(name)
{
    var str=document.cookie.split(";")
    for(var i=0;i<str.length;i++)
    {
        var str2=str[i].split("=");
        if(str2[0]==" "+name||str2[0]==name)return unescape(str2[1]);
    }
}
function showDialog(url,target,ajaxText){
    if(!target) target = "div.dialog_main";
    if(!ajaxText) ajaxText = '<div class="dialog_content"><p class="loading">正为你在处理数据, 请稍候...</p></div><a href="javascript:;" title="" onclick="closedialog();" class="Closeit">关闭</a>';
    if(!url)$('#dialog_clt .dialog_main').html(ajaxText);
    $('#dialog_clt').jqm({
        ajax:url,
        modal:true,
        toTop:true,
        target: target,
        ajaxText: ajaxText,
        onShow:myjqmOnShow,
        onLoad:myjqmOnLoad
        }).jqDrag('.jqDrag').jqmShow();
        $("#dialog_sharp").css('height', '100%');
}
var api    = 
{
    showtype    : 'newwindow',
    showbangding: function(utype,uid)
    {
        showbangdingForm(utype,uid);
    },
    ready	: function()
    {
		
    }
}
function showbangdingForm(type,uid)
{
	$("#LoginDialogIndex").dialog("close");
	$("#LoginDialogIndex").remove();
	var url = '/uajax/bangdingmodel/'+type+'/'+uid+'/jianfei';
	$.get(url, function(data) {
		$('body').append(data);
		$("#showBangdingDialog").dialog({
			resizable:false,
		    draggable:false,
		    modal:true
		});
		$(".dlclose").live("click",function(){
			$("#showBangdingDialog").remove();
			$("#showBangdingDialog").dialog("close");
		});
		$("#email").focus();
	});
}
function dialogBindingSignUp()
{
    var email    = $('.signuplogin input[name=email]').val();
    var nickname    = $('.signuplogin input[name=nickname]').val();
    var pwd    = $('.signuplogin input[name=passwd]').val();
    if(checkemail('register','emailreg')&&dialogchecknickname()&&checkpassword('passwdreg'))
    {
    }
    else
    {
        return false;
    }
    $.ajax(
    {
        type    : 'post',
        url    : '/?uajax/ajaxusername',
        data    : 'apiuid='+$("#api_uid").val()+'&apitype='+$("#api_type").val()+'&user='+email+'&pwd='+pwd+'&nickname='+nickname,
        dataType    : 'json',
        async    : false,
        success    : function (msg)
        {
            if(msg.status=='OK')
            {
                if(msg.data==='OK')
                {
                    window.location.href    = '/';
                }
                else
                {
                    // 添加失败
                    return false;
                }
            }
        }
    })
    return false;
}
function dialogBindingSignin()
{
	var email    = $('.signinlogin input[name=email]').val();
    var pwd    = $('.signinlogin input[name=passwd]').val();
    
    if(checkemail('haveBinding')&&checkpassword())
    {
        
    }
    else
    {
        return false;
    }
	$.ajax({
		type: "POST",
		url: "/ajax/bangding",
		data: "user=" + email + "&pwd=" + pwd + "&apiuid="+$("#api_uid").val()+"&apitype="+$("#api_type").val(),
		dataType:'json',
		success: function(obj){
			if (obj.status=='OK')
			{
				window.location.href=obj.data;
			}
			else
			{
				$('.signinlogin input[name=email]').parents('.iput').next().html(obj.data).addClass('lowrong').addClass('mll').removeClass('loright').removeClass('mtl15');
			}
		}
	});
}